home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-26 | 1.2 KB | 68 lines | [TEXT/CWIE] |
-
- // mail <chelly@eden.com> or surf http://www.eden.com/~chelly for feedback
- // free source code - do whatever you like with it
-
- // sequential access to file data
- // automatically swaps multi-byte integral types, so it's easier to use
-
- #include "stream.h"
- #include "byteorder.h"
-
- // ** These are the special two functions
-
- // read 2 bytes, then swap if required
- uint16 stream::get_mac_uint16()
- {
- uint16 val;
- get_bytes( &val, 2 );
- SwapIfRequired( &val );
- return val;
- }
-
- // read 4 bytes, then swap if required
- uint32 stream::get_mac_uint32()
- {
- uint32 val;
- get_bytes( &val, 4 );
- SwapIfRequired( &val );
- return val;
- }
-
- stream::stream( const char* path_of_file )
- {
- m_file = fopen( path_of_file, "rb" );
- assert( m_file );
- }
-
- stream::~stream()
- {
- int error = fclose( m_file );
- assert( !error );
- }
-
- uint8 stream::get_uint8()
- {
- uint8 val;
- get_bytes( &val, 1 );
- return val;
- }
-
- void stream::set_mark( long new_mark )
- {
- int error = fseek( m_file, new_mark, SEEK_SET );
- assert( !error );
- }
-
- void stream::skip( long n_bytes )
- {
- int error = fseek( m_file, n_bytes, SEEK_CUR );
- assert( !error );
- }
-
- void stream::get_bytes( void* storage, long n )
- {
- long read = fread( storage, n, 1, m_file );
- assert( n == 0 || read == 1 );
- }
-
-